Performs field processing on the LEADDocument object.
public void Process(
LEADDocument leadDoc,
IList<PageAlignment> formAlignment
)
leadDoc
The LEADDocument object.
formAlignment
A value that indicates the Form Alignment. It aligns the Master Form's fields to this form field. If it is null, the fields will be aligned based on the image resolution.
using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
using Leadtools.Forms.Common;
using Leadtools.Ocr;
using Leadtools.Forms.Processing;
using Leadtools.Forms.Recognition;
using Leadtools.Forms.Recognition.Barcode;
using Leadtools.Forms.Recognition.Ocr;
using Leadtools.Document;
public void ProcessLEADDoc()
{
string masterAtt = Path.Combine(LEAD_VARS.ImagesDir, @"Forms\MasterForm Sets\OCR\FFC-107.bin");
string masterFields = Path.Combine(LEAD_VARS.ImagesDir, @"Forms\MasterForm Sets\OCR\FFC-107.xml");
RasterCodecs codecs = new RasterCodecs();
FormProcessingEngine processingEngine = new FormProcessingEngine();
FormRecognitionEngine recognitionEngine = new FormRecognitionEngine();
FormRecognitionAttributes attributes = recognitionEngine.CreateForm(null);
FormRecognitionAttributes masterAttributes = new FormRecognitionAttributes();
// Set Master Form Data from file and load fields
masterAttributes.SetData(File.ReadAllBytes(masterAtt));
processingEngine.LoadFields(masterFields);
// Dropout any green pixels in the page
FormDropoutColor dropColor = new FormDropoutColor(0, 20, 0, 0, 230, 0);
processingEngine.Pages[0].DropoutColors.AddDropoutColor(dropColor);
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
{
ocrEngine.Startup(codecs, null, null, LEAD_VARS.OcrLEADRuntimeDir);
OcrObjectsManager objectsManager = new OcrObjectsManager(ocrEngine);
objectsManager.Engine = ocrEngine;
recognitionEngine.ObjectsManagers.Add(objectsManager);
// Load the LEADDocument from file with default options
LoadDocumentOptions loadOptions = new LoadDocumentOptions();
LEADDocument leadDoc = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, @"Forms\Filled Forms\FCC-107_OCR_Filled.tif"), loadOptions);
// Add the lead document to the attributes object to compare
recognitionEngine.OpenForm(attributes);
recognitionEngine.AddFormPage(0, attributes, leadDoc, null, null);
recognitionEngine.CloseForm(attributes);
// Compare master attributes with form attributes
FormRecognitionResult recognitionResult = recognitionEngine.CompareForm(masterAttributes, attributes, null);
if (recognitionResult.PageResults.Count == 0)
{
Console.WriteLine("Pages count is 0.");
return;
}
Console.WriteLine("LEADDoc recognized with confidence of {recognitionResult.PageResults[0].Confidence}\n");
List<PageAlignment> pageAlignments = new List<PageAlignment>();
pageAlignments.Add(recognitionResult.PageResults[0].Alignment);
processingEngine.OcrEngine = ocrEngine;
// Process first page
processingEngine.Process(leadDoc, 0, 0, pageAlignments);
leadDoc.Dispose();
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime";
}